// pages/goods_state/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: "",
    shipCoName: "",
    shipSN: "",
    logo: "",
    goodsList: [],
    oid: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var oid = options.oid;
    that.setData({
      oid: oid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.setNavigationBarTitle({
      title: '查看物流',
    })
    this.getGoodsInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //获取物流信息
  getGoodsInfo: function () {
    var that = this;
    wx.request({
      url: app.globalData.host + '/api/order/GetOrderLogistics?oid=' + that.data.oid,
      success: function (res) {
        if(res.data.Code == 0){
          var phone = res.data.Data.Phone;
          var shipCoName = res.data.Data.ShipCoName;
          var shipSN = res.data.Data.ShipSN;
          var logo = 'https://static.711688.net.cn/upload/store/' + app.globalData.storeId + '/product/show/thumb800_800/' + res.data.Data.ShowImg;
          var goodsList = res.data.Data.Traces;
          for (var i = 0; i < goodsList.length; i++) {
            goodsList[i].detailTime = goodsList[i].AcceptTime.substr(11, 5)
            goodsList[i].AcceptTime = goodsList[i].AcceptTime.substr(5, 5)
          }
          that.setData({
            phone: phone,
            shipCoName: shipCoName,
            shipSN: shipSN,
            logo: logo,
            goodsList: goodsList.reverse()
          })
        }else{
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.navigateBack({
                  delta: 1,
                })
              }
            }
          })
        }
      },
    })
  },
  //一键复制
  clipboardData: function () {
    var that = this;
    wx.setClipboardData({
      data: that.data.shipSN,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            
          }
        })
      }
    })
  }
})